@echo off
setlocal enabledelayedexpansion

set d=%date:~0,4%%date:~5,2%%date:~8,2%
set BACKUP_DIR=C:\backup
set FILE_NAME=%d%

rem 删除15天之前的.dmp和.log文件。
forfiles /p "C:\backup" /s /m *.dmp /d -15 /c "cmd /c del @path"
forfiles /p "C:\backup" /s /m *.log /d -15 /c "cmd /c del @path"


rem 获取当天时间，来判断是增量还是全量备份。
set DAYS=Sun Mon Tue Wed Thu Fri Sat
set TYPES=incremental complete incremental incremental incremental cumulative incremental
for /f "tokens=1-3 delims=/ " %%d in ('date /t') do (
    set /a "yy=%%f, mm=10%%d %% 100, dd=10%%e %% 100"
)

set /a "dayOfWeek=(dd+2*mm+3*(mm+1)/5+yy+yy/4-yy/100+yy/400+1) %% 7"

for /f "tokens=%dayOfWeek% delims= " %%a in ("%DAYS%") do (
    set day=%%a
)

for /f "tokens=%dayOfWeek% delims= " %%b in ("%TYPES%") do (
    set type=%%b
)

rem 执行备份
exp interlib/interlib@192.168.48.252:1521/interlib inctype=%type% file=%BACKUP_DIR%\interlib_%FILE_NAME%.dmp   log=%BACKUP_DIR%\interlib_%FILE_NAME%_exp.log